<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script type="text/javascript" src="../js/vue.js"></script>
  </head>
  <body>
    <div id="app">
      姓：<input type="text" v-model="firstName" /> + 名：<input
        type="text"
        v-model="lastName"
      />
      = <span>{{ fullName }}</span><br /><br />
      <button @click="changeName">改名卡</button>
    </div>

    <script>
      const app = new Vue({
        el: "#app",
        data: {
          firstName: "刘",
          lastName: "备",
        },
        methods: {
          changeName() {
            this.fullName = "黄忠";
          },
        },
        computed: {
          // 简写 → 获取，没有配置设置的逻辑
          // fullName () {
          //   return this.firstName + this.lastName;
          // }
          fullName:{
            get(){
                return this.firstName + this.lastName;
              },
              set(value){
                this.firstName = value.slice(0,1);
                this.lastName = value.slice(1,2);
              }
            }
        },
        
        });
    </script>
  </body>
</html>
